package com.yuren.codecrushlearn.Q5100;

/**
 * Created with Intellij IDEA.
 * Description:
 *
 * @author Sleepy Code Tom
 * @date 2025-04-05 22:18
 */
public class Q5152 {

    /**
     * 插入排序
     *
     * @param arr
     * @param n
     */
    public void insertSort(int[] arr, int n) {
        if (n <= 1) return;

        for (int i = 1; i < n; ++i) {
            int value = arr[i];
            int j = i - 1;
            // 查找要插入的位置并移动数据
            for (; j >= 0; --j) {
                if (arr[j] > value) {
                    arr[j + 1] = arr[j];
                } else {
                    break;
                }
            }
            arr[j + 1] = value;
        }
    }
}
